<?php defined('IN_LK') or die('Access Denied');?>
<?php include self::admin_t('header');?>

<ul class="main_nav">
  <li><a href="?m=admin&c=role_manage&ac=1" target="_self" <?php echo $ac == 1 ? 'class="select"' : '';?>>角色管理</a></li>
  <li><a href="?m=admin&c=role_manage&ac=2" target="_self" <?php echo $ac == 2 ? 'class="select"' : '';?>>添加角色</a></li>
</ul>
<div class="c"></div>
<?php if($ac == 1){?>
<div class="table-list">
  <form action="?m=admin&c=role_manage&a=do_listorder" method="post">
    <table width="100%" cellspacing="0">
      <thead>
        <tr>
          <th width="7%">排序</th>
          <th width="8%">序号</th>
          <th align="left" width="20%">角色名称</th>
          <th align="left" width="">角色描述</th>
          <th width="70">状态</th>
          <th width="300">管理操作</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach($role_list as $role){?>
        <tr>
          <td align="center"><input type="text" class="input input_short input_short_center" name="listorder[<?php echo $role['roleid'];?>]" value="<?php echo $role['listorder'];?>" size="3" /></td>
          <td align="center"><?php echo $role['roleid'];?></td>
          <td><?php echo $role['rolename'];?></td>
          <td><?php echo $role['description'];?></td>
          <td align="center">
          <?php if(1 == $role['roleid']){?><span class="pointer g8">已启用</span><?php }else{?>
          	<?php if(0 == $role['disabled']){?><a href="javascript:void(0);" onclick="disabled(<?php echo $role['roleid'];?>, '<?php echo $role['rolename'];?>');"><span class="green">已启用</span></a><?php }else{?>
            <a href="javascript:void(0);" onclick="enable(<?php echo $role['roleid'];?>);"><span class="red">已停用</span></a><?php }}?>
          </td>
          <td align="center"><?php if(1 == $role['roleid']){?><span class="pointer g8">权限设置</span> | <span class="pointer g8">栏目权限</span> | <span class="pointer g8">成员管理</span> | <span class="pointer g8">修改</span> | <span class="pointer g8">删除</span><?php }else{?>权限设置 | 栏目权限 | <a href="?m=admin&c=role_manage&a=member_manage&roleid=<?php echo $role['roleid']?>">成员管理</a> | <a href="?m=admin&c=role_manage&a=edit_role&roleid=<?php echo $role['roleid']?>">修改</a> | <a href="javascript:void(0);" onclick="del_role(<?php echo $role['roleid'];?>, '<?php echo $role['rolename'];?>');">删除</a><?php }?></td>
        </tr>
        <?php }?>
      </tbody>
    </table>
    <div class="bot">
      <input type="submit" class="btn" name="dosubmit" id="dosubmit" value="排序" />
    </div>
  </form>
</div>
<script typr="text/javascript">
function enable(roleid)
{
	$.get('?m=admin&c=role_manage&a=change_status&disabled=0&roleid=' + roleid, function (data)
	{
		if(data == "1")
		{
			parent.main.location.reload();
		}
	});
}
function disabled(roleid, rolename)
{
	window.top.art.dialog(
	{
		title:'禁用 - ' + rolename,
		content: '你确定要禁用 ' + rolename + ' 吗？ <br />如果角色 "' + rolename + '" 下有成员将禁止操作',
		fixed:true,
		id:'disabled'
	},
	function ()
	{
		$.get('?m=admin&c=role_manage&a=change_status&disabled=1&roleid=' + roleid, function(data)
		{
			if(data == "1")
			{
				parent.main.location.reload();
			}
		});
		
	},
	function()
	{
		window.top.art.dialog({id:'disabled'}).close();
	});
}
function del_role(roleid, rolename)
{
	window.top.art.dialog(
	{
		title:'删除角色 - ' + rolename,
		content: '你确定要删除 ' + rolename + ' 吗？ <br />如果角色 "' + rolename + '" 下有成员将禁止操作',
		fixed:true,
		id:'del_role'
	},
	function ()
	{
		$.get('?m=admin&c=role_manage&a=delete_role&roleid=' + roleid, function(data)
		{
			if(data == "1"){parent.main.location.reload();}
		});},function(){window.top.art.dialog({id:'del_role'}).close();});
}
</script>
<?php }else if(in_array($ac, array(2,3))){?>
<?php if(isset($edit)){?>
<div class="message msg" id="login_error"><span class="green">编辑角色 <?php echo $rolename;?></span></div>
<?php }?>
<form action="?m=admin&c=role_manage&a=<?php echo isset($edit) ? 'edit_role' : 'add_role';?>" method="post" name="myform" id="myform">
  <dl class="form_list">
    <dd><span class="w8 left">角色名称</span>
      <input type="text" class="input" name="info[rolename]" id="rolename" value="<?php echo isset($rolename) ? $rolename : ''?>" size="20" />
      <?php if(isset($edit)){?><input type="hidden" name="info[roleid]" value="<?php echo $roleid;?>" /><?php }?>
    </dd>
    <dd> <span class="left w8">角色描述</span>
      <textarea name="info[description]" id="description" cols="60" rows="4"><?php echo isset($description) ? $description : ''?></textarea>
    </dd>
    <dd> <span class="left w8">是否启用</span>
      <input type="radio" class="input" name="info[disabled]" id="disabled0" value="0" <?php  echo isset($disabled) && $disabled != 0 ? '' : 'checked="checked"'?> /><label for="disabled0">启用</label>
      <input type="radio" class="input" name="info[disabled]" id="disabled1" value="1" <?php  echo isset($disabled) && $disabled == 1 ? 'checked="checked"' : ''?> /><label for="disabled1">禁用</label>
    </dd>
    <dd> <span class="left w8">排序</span>
    <input type="text"  class="input" name="info[listorder]" id="listorder" value="<?php echo isset($listorder) ? $listorder : 0;?>" size="3" />
    </dd>
    <dd>
      <input type="submit" class="btn" name="dosubmit" id="dosubmit" value="提交" />
    </dd>
  </dl>
</form>
<script type="text/javascript">
$(function()
{
	$.formValidator.initConfig({autotip:true,formid:"myform",onerror:function(msg){}});
	$("#rolename").formValidator({onshow:"请输入角色名称",onfocus:"角色名称不能为空。"}).inputValidator({min:1,max:20,onerror:"角色名称不能为空。"});
});
</script>
<?php }?>
<?php include self::admin_t('footer');?>
